<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="历史版本" prop="hisVersion">
        <el-select @change="changeHisVersion($event)" v-model="queryParams.hisVersion" placeholder="请选择历史版本号" clearable>
          <el-option
            v-for="dict in reductionVersions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
            @keyup.enter.native="handleQuery"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="对应编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入基础数据对应的编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模块名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入模块名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-select v-model="queryParams.version" placeholder="请选择版本号" clearable>
          <el-option
            v-for="dict in dict.type.report_version"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
	    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reportworld:database:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="butloading"
          @click="downUpgradeToolsZip"
          v-hasPermi="['reportworld:upgradetoolszip']"
        >导出ZIP文件</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :loading="butloading"
          @click="databaseDataCheckSql"
          v-hasPermi="['reportworld:databaseCheck:data:checkSql']"
        >更新校验语句</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="butloading"
          @click="databaseDataCheck"
          v-hasPermi="['reportworld:databaseCheck:data:check']"
        >数据校验</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border="border"
       max-height="550px"
      v-if="refreshTable"
      v-loading="loading"
      :data="databaseList"
      row-key="id"
      :default-expand-all="isExpandAll"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column v-hasPermi="['reportworld:database:query','reportworld:database:add',
      'reportworld:database:edit','reportworld:database:remove','reportworld:databaseCheck:list','reportworld:dispose:list',
      'reportworld:database:compareconfig','reportworld:database:structureDataBase']"
        label="操作" type="" align="center" width="260px" class-name="small-padding fixed-width">
        <template  slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row,false)"
            v-hasPermi="['reportworld:database:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAdd(scope.row)"
            v-hasPermi="['reportworld:database:add']"
          >新增</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['reportworld:database:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['reportworld:database:remove']"
          >删除</el-button>
          <el-button v-if=" scope.row.code != null && scope.row.code != ''"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="databaseCheck(scope.row)"
            v-hasPermi="['reportworld:databaseCheck:list']"
          >校验管理</el-button>
          <el-button v-if=" scope.row.code != null && scope.row.code != ''"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="databaseDispose(scope.row)"
            v-hasPermi="['reportworld:dispose:list']"
          >页面配置</el-button>
          <el-button v-if="scope.row.code != 'REPORT_WORLD_TABLE' && scope.row.code !='REPORT_WORLD_TABLE_DETAIL'
               && scope.row.code != 'REPORT_WORLD_DATASQL' && scope.row.code != 'REPORT_WORLD_TABLE_INDEXED'  && scope.row.code != null && scope.row.code != ''"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getCompareconfig(scope.row)"
            v-hasPermi="['reportworld:database:compareconfig']"
          >升级策略</el-button>
          <el-button  v-if=" scope.row.code != null && scope.row.code != ''
               &&  scope.row.code != 'REPORT_WORLD_TABLE' && scope.row.code !='REPORT_WORLD_TABLE_DETAIL'
               && scope.row.code != 'REPORT_WORLD_DATASQL' && scope.row.code != 'REPORT_WORLD_TABLE_INDEXED'
               && 2==scope.row.structure"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="structureDataBase(scope.row)"
                     v-hasPermi="['reportworld:database:structureDataBase']"
          >基础数据构建</el-button>

         <!-- <el-dropdown v-if="scope.row.parentId !== '0'" size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['reportworld:dispose:list',
          'reportworld:databaseCheck:list','reportworld:database:compareconfig']">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item  command="databaseCheck" icon="el-icon-edit"
                                 v-hasPermi="['reportworld:databaseCheck:list']">校验管理</el-dropdown-item>
              <el-dropdown-item  command="databaseDispose" icon="el-icon-check"
                                v-hasPermi="['reportworld:dispose:list']">页面配置</el-dropdown-item>
              <el-dropdown-item  command="databaseCompareconfig" icon="el-icon-edit"
                                 v-hasPermi="['reportworld:database:compareconfig']">升级策略</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>-->
        </template>
      </el-table-column>
      <el-table-column label="编码名称" align="center" prop="name"  width="180px" :show-overflow-tooltip="true"/>
      <el-table-column label="对应编码" align="center" prop="code"  width="180px" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <a @click="handleDatabasecode(scope.row.code)" style="color:blue;cursor:pointer;font-size: 12px;"
             v-if="scope.row.code != 'REPORT_WORLD_TABLE' && scope.row.code !='REPORT_WORLD_TABLE_DETAIL'
               && scope.row.code != 'REPORT_WORLD_DATASQL'  && scope.row.code != 'REPORT_WORLD_TABLE_INDEXED'">{{scope.row.code ? scope.row.code.replace('RW_DB_',''):scope.row.code }}</a>
          <span v-else>{{ scope.row.code ? scope.row.code.replace('RW_DB_',''):scope.row.code }}</span>
        </template>
      </el-table-column>
      <el-table-column label="顺序" align="center" prop="orderNum" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="版本号" width="150" align="center" prop="version">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.report_version" :value="scope.row.version"/>
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加人" width="150" align="center" prop="createBy" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="编辑时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="编辑人" width="150" align="center" prop="updateBy" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
    </el-table>

    <!-- 添加或修改基础数据对话框 -->
    <el-dialog   :title="title" :close-on-click-modal ="false" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="上级编码" prop="parentId">
              <treeselect v-model="form.parentId" :options="databaseOptions" :normalizer="normalizer"
                          placeholder="请选择上级编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="对应编码" prop="code"
                          v-if="form.parentId == '0' ? false:true"
                          :rules="form.parentId != '0' ? [{ required: true, message: '对应编码不能为空'}]:rules.target">
              <el-input clearable v-model="form.code" placeholder="请输入基础数据对应的编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="编码名称" prop="name">
              <el-input clearable v-model="form.name" placeholder="请输入模块名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="顺序" prop="orderNum">
              <el-input-number clearable style="width: 220px" v-model="form.orderNum" controls-position="right" :min="0"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.sys_common_status"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区分数据库" prop="dataBaseType">
              <el-radio-group v-model="form.dataBaseType">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内部使用" prop="isSystem">
              <el-radio-group v-model="form.isSystem">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{dict.label}}
                </el-radio>
              </el-radio-group>
              <span slot="label">
                <el-tooltip content="系统内部使用的需要有权限才能显示的节点" placement="top">
                <i class="el-icon-question"></i>
                </el-tooltip>
                内部使用
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="版本号" prop="version">
              <el-select :disabled="true" clearable v-model="form.version" placeholder="请选择版本号">
                <el-option
                  v-for="dict in dict.type.report_version"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input maxlength="500" clearable v-model="form.remark" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="isUpdate" :loading="butloading" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- SQL检查和执行结果 -->
    <el-dialog  :title="titleMsg"   :visible.sync="openMsg" :close-on-click-modal ="false" width="1000px" height="500px" append-to-body>
      <el-col :span="24" style="height:500px ">
        <textarea  v-model="msg" style="width:100%;height: 492px" ></textarea>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button ref="upload" type="primary" :loading="butloading" @click="doDownUpgradeToolsZip">继 续</el-button>
        <el-button @click="openMsg = false">关 闭</el-button>
      </div>
    </el-dialog>


    <!-- 策略文件 -->
    <el-dialog  :title="titleCompareconfig"   :visible.sync="openCompareconfig" :close-on-click-modal ="false" width="1200px" height="500px" append-to-body>
      <el-form ref="formcompareconfig" :model="formcompareconfig" :rules="rulescompareconfig" label-width="140px">
        <el-row>
          <el-form-item label="策略信息" prop="json">
          <el-col :span="24">
            <monaco-editor  ref="monacoEditor"  style="border:1px solid #000;"
                            :opts="opts"></monaco-editor>
          </el-col>
          </el-form-item>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary"  v-hasPermi="['reportworld:database:compareconfig:edit']" @click="submitCompareconfigForm">确 定</el-button>
        <el-button @click="openCompareconfig = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listDatabase, getDatabase, delDatabase, addDatabase,updateDatabase,getCompareconfig,updateCompareconfig,structureDataBase,init} from "@/api/reportworld/database";
import { databaseDataCheckSql,databaseDataCheck} from "@/api/reportworld/databaseCheck";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import monacoEditor from '@/components/SqlEditor';

export default {
  name: "Database",
  dicts: ['sys_common_status','sys_yes_no','report_version'],
  components: {
    Treeselect,
    monacoEditor
  },
  data() {
    return {
      butloading:false,
      isUpdate:false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 基础数据表格数据
      databaseList: [],
      // 基础数据树选项
      databaseOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 校验结果弹出框
      openMsg:false,
      msg:"",
      titleMsg: "",
      checkPass:false,
      // 策略文件
      titleCompareconfig:"",
      openCompareconfig:false,
      // 是否展开，默认全部展开
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      reductionVersions:[],
      checkVersions:[],
      formVersion:{},
      formVersionCheck:{},
      opts: { //编辑器
        value: '',
        readOnly: false, // 是否可编辑
        language: 'json', // 语言类型
        theme: 'vs', // 编辑器主题
        lineNumbers: "on", // 行号 取值
        height:500
      },
      // 查询参数
      queryParams: {
        parentId: null,
        code: null,
        name: null,
        orderNum: null,
        status: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null,
        hisVersion:null,
      },
      // 表单参数
      form: {},
      formcompareconfig:{},
      rulescompareconfig:{},
      // 表单校验
      rules: {
        parentId: [
          {required: true, message: "上级编码不能为空", trigger: "change"}
        ],
        code: [
          {required: true, message: "对应编码不能为空", trigger: "change"}
        ],
        name: [
          {required: true, message: "编码名称不能为空", trigger: "change"}
        ],
        orderNum: [
          {required: true, message: "显示顺序不能为空", trigger: "change"}
        ]
      },
      rulesVersion: {
        version:[{ required: true, message: '请选择要导出的版本号',trigger: 'blur'}]
      },
      rulesVersionCheck: {
        versions:[{ required: true, message: '请选择要校验的版本号',trigger: 'blur'}]
      }
    };
  },
  created() {
    this.getList();
    this.init();
  },
  methods: {
    changeHisVersion(value){
      this.queryParams.hisVersion=value;
      this.init();
      this.getList();
    },
    init(){
      init(this.queryParams).then(response => {
        this.reductionVersions=response.reductionVersions;
        this.checkVersions=response.checkVersions;
        this.hisVersions=response.hisVersions;
    });
    },
    /** 查询基础数据列表 */
    getList() {
      this.loading = true;
      listDatabase(this.queryParams).then(response => {
        this.databaseList = this.handleTree(response.data, "id", "parentId");
        this.loading = false;
      });
    },
    /** 转换基础数据数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
	/** 查询基础数据下拉树结构 */
    getTreeselect() {
      listDatabase().then(response => {
        this.databaseOptions = [];
        const data = { id: 0, name: '顶级节点', children: [] };
        data.children = this.handleTree(response.data, "id", "parentId");
        this.databaseOptions.push(data);
      });
    },
    // 获取单个表的策略配置信息
    getCompareconfig(row){
      const code = row.code;
      getCompareconfig(code).then(response => {
        this.opts.value= '';
        this.opts.value= response.data;
        this.openCompareconfig=true;
        this.titleCompareconfig="升级策略信息";
    });
    },
    structureDataBase(row){
      const code = row.code;
      structureDataBase(code,this.queryParams.hisVersion).then(response => {
        this.$modal.msgSuccess("构建成功");
    });
      },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openMsg =false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentId: null,
        code: null,
        name: null,
        orderNum: null,
        status: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null,
        dataBaseType:null,
        isSystem:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
      /**查询数据*/
      handleDatabasecode(code){
        //this.$router.push("/reportworld/data-base/code/" + code);
        this.$router.push({ path:"/reportworld/data-base/code/" + code+this.queryParams.hisVersion,
          query: {code:code,hisVersion:this.queryParams.hisVersion} });
      },
    databaseCheck(row){
      const code = row.code;
     // this.$router.push("/reportworld/database-check/tableCode/" + code);
      this.$router.push({ path:"/reportworld/database-check/tableCode/" + code+this.queryParams.hisVersion,
        query: {code:code,hisVersion:this.queryParams.hisVersion} });
    } ,
    databaseDispose(row){
      const code = row.code;
     // this.$router.push("/reportworld/database-dispose/tableName/" + code);
      this.$router.push({ path:"/reportworld/database-dispose/tableName/" + code+this.queryParams.hisVersion
        , query: {code:code,hisVersion:this.queryParams.hisVersion} });
    } ,
    // 更多操作触发
  /*  handleCommand(command, row) {
      const code = row.code;
      switch (command) {
        case "databaseDispose":
          this.$router.push("/reportworld/database-dispose/tableName/" + code);
          break;
        case "databaseCheck":
          this.$router.push("/reportworld/database-check/tableCode/" + code);
          break;
        case "databaseCompareconfig":
          this.getCompareconfig(code);
        default:
          break;
      }
    },*/
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.id) {
        this.form.parentId = row.id;
      } else {
        this.form.parentId = 0;
      }
      this.open = true;
      this.title = "添加基础数据";
      this.isUpdate =true;
      this.form.status = parseInt(this.dict.type.sys_common_status[0].value);
      this.form.dataBaseType = parseInt(this.dict.type.sys_yes_no[1].value);
      this.form.isSystem = parseInt(this.dict.type.sys_yes_no[1].value);
      this.form.version = this.dict.type.report_version[0].value;
      if(this.queryParams.hisVersion){
        this.form.version =this.queryParams.hisVersion;
      }
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row,isUpdate) {
      this.reset();
      this.getTreeselect();
      if (row != null) {
        this.form.parentId = row.id;
      }
      this.queryParams.id=row.id;
      getDatabase(this.queryParams).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改基础数据";
      this.isUpdate =true;
      if(isUpdate == false){
        this.title = "基础数据详情";
        this.isUpdate =false;
      }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.butloading=true;
          this.form.hisVersion =this.queryParams.hisVersion;
          if (this.form.id != null) {
            updateDatabase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {this.butloading=false});
          } else {
            addDatabase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {this.butloading=false});
          }
        }
      });
    },
    submitCompareconfigForm(){ //修改策略文件
      const json=this.$refs.monacoEditor.getVal();
      if(!json){
        this.$modal.msgError("策略文件不能为空");
        return;
      }
      try {
        if(json){
          JSON.parse(json) // 如果不是json字符串就会抛异常
        }
      } catch(e) {
        this.$modal.msgError("策略文件必须为JSON格式");
        return;
      }
      updateCompareconfig(json).then(response => {
        this.$modal.msgSuccess("修改策略文件成功");
        this.openCompareconfig = false;
    });
    },
    downUpgradeToolsZip() {
      const hisVersion=this.queryParams.hisVersion ? this.queryParams.hisVersion:this.dict.type.report_version[0].value;
      const queryParams=JSON.stringify(this.queryParams);
      this.butloading=true;
      this.$modal.loading("正在检查数据中，请稍候...");
      this.$modal.confirm("是否确认导出【"+hisVersion+"】资源文件压缩包？").then(function() {
        return databaseDataCheck(queryParams);
      }).then(response => {
        if(response.result== false){
        this.openMsg = true;
        this.titleMsg ="基础数据校验信息";
        this.msg ="基础数据校验未通过，不能导出资源文件!原因：\r\n"+response.msgInfo;
        this.checkPass=false;
      }else{
        if(response.msgInfo){
          this.openMsg = true;
          this.checkPass=true;
          this.titleMsg ="基础数据校验信息";
          this.msg ="基础数据校验通过，点击继续按钮导出资源文件!\r\n"+response.msgInfo;
        }else{
           this.$modal.closeLoading();
           this.butloading=false;
           this.openMsg = false;
           this.doDownUpgradeToolsZip();
        }
      }
    }).finally(() => { this.$modal.closeLoading();this.butloading=false});
    },
    doDownUpgradeToolsZip(){
        this.openMsg = false;
        const hisVersion=this.queryParams.hisVersion ? this.queryParams.hisVersion:this.dict.type.report_version[0].value;
        this.download('reportworld/database/downUpgradeToolsZip', {
          ...this.queryParams
      }, hisVersion+`_${new Date().getTime()}.zip`)
    },
    databaseDataCheckSql(){ // 更新校验语句
      const hisVersion=this.queryParams.hisVersion ? this.queryParams.hisVersion:this.dict.type.report_version[0].value;
      const queryParams=JSON.stringify(this.queryParams);
      this.butloading=true;
      this.$modal.loading("正在更新校验语句，请稍候...");
      this.$modal.confirm("是否确认更新【"+hisVersion+"】校验语句？").then(function() {
        return databaseDataCheckSql(queryParams);
      }).then(response => {
        this.$modal.msgSuccess("更新校验语句成功");
        this.$modal.closeLoading();
        this.butloading=false
    }).finally(() => { this.$modal.closeLoading();this.butloading=false});
    },
    databaseDataCheck(){
      const hisVersion=this.queryParams.hisVersion ? this.queryParams.hisVersion:this.dict.type.report_version[0].value;
      const queryParams=JSON.stringify(this.queryParams);
      this.butloading=true;
      this.$modal.loading("正在检查中，请稍候...");
      this.$modal.confirm("是否确认检查【"+hisVersion+"】基础数据？").then(function() {
        return databaseDataCheck(queryParams);
      }).then(response => {
          if(response.msgInfo){
            this.openMsg = true;
            this.titleMsg ="基础数据校验信息";
            this.msg = response.msgInfo;
         }else{
            this.$modal.msgSuccess("基础数据校验通过");
          }
          this.$modal.closeLoading();
          this.butloading=false
    }).finally(() => { this.$modal.closeLoading();this.butloading=false});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const hisVersion=this.queryParams.hisVersion;
      this.$modal.confirm('是否确认删除数据项？').then(function() {
        return delDatabase(row.id,hisVersion);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
